﻿using Adams.Admin.Business.Events;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Adams.Shared.Entities.Events;

namespace Adams.Tests.Admin.Business.Events
{
    
    
    /// <summary>
    ///This is a test class for CreateEventUnitTest and is intended
    ///to contain all CreateEventUnitTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CreateEventUnitTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GenerateOccurances
        ///</summary>
        [TestMethod()]
        public void GenerateOccurancesUnitTest()
        {
            #region Test - No Repeat
            Event oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = false,
                RepeatType = 0,
                RepeatEndType = 0,
                RepeatEndOccurences = 0,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 0,
                RepeatStartsOn = DateTime.Now,
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            int expected = 1;
            int actual;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Daily
            
            #region Test - Daily, Repeat 1, Ends Never
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 1,
                RepeatEndType = 1,
                RepeatEndOccurences = 0,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            DateTime d = new DateTime(2010, 1, 1, 11, 30, 0);
            expected = Adams.Shared.DateHelper.DiffDays(d, DateTime.UtcNow.AddYears(5)) + 1;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Daily, Repeat 2, Ends After 5
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 1,
                RepeatEndType = 2,
                RepeatEndOccurences = 5,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 2,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            d = new DateTime(2010, 1, 1, 11, 30, 0);
            expected = 5;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Daily, Repeat 2, Ends On
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 1,
                RepeatEndType = 3,
                RepeatEndOccurences = 0,
                RepeatEndDate = new DateTime(2010, 1, 29, 13, 00, 0),
                RepeatEvery = 2,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            expected = 15;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion
            
            #endregion

            #region Weekly

            #region Test - Weekly, Repeat 1, On MW, Ends Never
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 2,
                RepeatEndType = 1,
                RepeatEndOccurences = 0,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = true,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = true,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            expected = 668;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Weekly, Repeat 2, On TT, Ends After 5
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 2,
                RepeatEndType = 2,
                RepeatEndOccurences = 5,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 2,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = true,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = true,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            d = new DateTime(2010, 1, 1, 11, 30, 0);
            expected = 5;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Weekly, Repeat 1, On FSS, Ends On
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 2,
                RepeatEndType = 3,
                RepeatEndOccurences = 0,
                RepeatEndDate = new DateTime(2010, 1, 31, 13, 00, 0),
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = true,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = true,
                RepeatWeeklySat = true,
                RepeatMonthlyBy = 0
            };
            expected = 15;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #endregion

            #region Monthly

            #region Test - Monthly, Repeat 1, On day, Ends Never
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 3,
                RepeatEndType = 1,
                RepeatEndOccurences = 0,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = true,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = true,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 1
            };
            expected = 77;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Monthly, Repeat 2, On day of week, Ends After 5
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 5, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 3,
                RepeatEndType = 2,
                RepeatEndOccurences = 5,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 2,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = true,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = true,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 2
            };
            expected = 5;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Monthly, Repeat 1, On 5th day of week, Ends On
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 31, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 31, 12, 30, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 3,
                RepeatEndType = 3,
                RepeatEndOccurences = 5,
                RepeatEndDate = new DateTime(2010, 10, 1, 11, 30, 0),
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 31, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = true,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = true,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 2
            };
            expected = 9;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #endregion

            #region Yearly

            #region Test - Yearly, Repeat 1, Ends Never
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 4,
                RepeatEndType = 1,
                RepeatEndOccurences = 0,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            expected = 7;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Yearly, Repeat 2, Ends After 5
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 4,
                RepeatEndType = 2,
                RepeatEndOccurences = 5,
                RepeatEndDate = DateTime.Now,
                RepeatEvery = 2,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            d = new DateTime(2010, 1, 1, 11, 30, 0);
            expected = 5;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #region Test - Yearly, Repeat 1, Ends On
            oEvent = new Adams.Shared.Entities.Events.Event()
            {
                ID = 0,
                Title = "",
                ShortDescription = "",
                Location = "",
                Description = "",
                StartDate = new DateTime(2010, 1, 1, 11, 30, 0),
                EndDate = new DateTime(2010, 1, 1, 13, 00, 0),
                TimeZone = -5,
                IsAllDay = false,
                IsRepeat = true,
                RepeatType = 4,
                RepeatEndType = 3,
                RepeatEndOccurences = 0,
                RepeatEndDate = new DateTime(2015, 1, 29, 13, 00, 0),
                RepeatEvery = 1,
                RepeatStartsOn = new DateTime(2010, 1, 1, 11, 30, 0),
                RepeatWeeklySun = false,
                RepeatWeeklyMon = false,
                RepeatWeeklyTeu = false,
                RepeatWeeklyWed = false,
                RepeatWeeklyThu = false,
                RepeatWeeklyFri = false,
                RepeatWeeklySat = false,
                RepeatMonthlyBy = 0
            };
            expected = 6;
            actual = CreateEvent.GenerateOccurances(oEvent).Count;
            Assert.AreEqual(expected, actual);
            #endregion

            #endregion
        }
    }
}
